% CREATE TARGET PATHS INCLUDING OCCLUDER POSITION FOR PLOTTING

FpC = trialsummary(1,1).speed.fpc;   % frames per cycle

msPerCycle = round((1000/60)*FpC);

a = 1;
for t = 1:3*msPerCycle + 1
    target18.time(t,1) = t - 1;
    % calculate cos function of x and multiply by no of pixels in half of
    % the stimulus path (0.5 x 0.75 x scnw)
    target18.X(t,1) = (0.5*0.75*scnw)*cos(((t-1)*60)/(FpC*1000)*2*pi);
    % calculate when occluder is present
    if -(scnw/(10/3)) < target18.X(t,1) && target18.X(t,1) < 0
        target18.occluder(t,1) = 1;
    else 
        target18.occluder(t,1) = 0;
    end
    % convert to logical
    target18.occluder = target18.occluder==1 ;
end

% tabulate x and y values of occluder for patch plotting later
for t = 1:3*msPerCycle
    if target18.occluder(t+1,1) == 1 && target18.occluder(t,1) == 0
        target18.plotocc.x(a,1) = t + 1;
        target18.plotocc.x(a,4) = t + 1;
    end
    if target18.occluder(t+1,1) == 0 && target18.occluder(t,1) == 1
        target18.plotocc.x(a,2) = t;
        target18.plotocc.x(a,3) = t;
        a = a + 1;
    end    
end

n_occluders = a - 1;                    % number of occluders in 3 cycles (i.e. 6)

target18.plotocc.y(1:a-1,1:2) = -600;
target18.plotocc.y(1:a-1,3:4) = 600;
target18.plotocc.yvel(1:a-1,1:2) = -40;
target18.plotocc.yvel(1:a-1,3:4) = 40;

target18.one = target18.X(1:msPerCycle,1);

% CALCULATE TARGET VELOCITIES

target18.Xvel = velocity(target18.X,5,scnw,scnwcm,view_dist);

target18.onevel = target18.Xvel(1:msPerCycle,1);
